package com.example.demo.heartbeat;

import com.alibaba.fastjson.JSONObject;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 客户端编码器
 * @author kh
 * @data 2021-08-10 16:40:21
 *
 */
public class HeartBeatEncode extends MessageToByteEncoder<HeartBeat> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, HeartBeat heartbeat, ByteBuf byteBuf) throws Exception {
        String jsonString = JSONObject.toJSONString(heartbeat);
        byteBuf.writeBytes(jsonString.getBytes());
    }
}
